﻿<%@ WebHandler Language="C#" Class="DownloadHandler" %>

using System;
using System.Web;
using System.Configuration;

public class DownloadHandler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        if (context.Request.QueryString["Fn"] != null && context.Request.QueryString["Bid"] != null)
        {
            string filename = System.Web.HttpUtility.UrlDecode(context.Request.QueryString["Fn"]);
            string foldername = System.Web.HttpUtility.UrlDecode(context.Request.QueryString["Bid"]);
            
            context.Response.ClearHeaders();
            context.Response.Clear();            
            context.Response.Expires = 0;
            context.Response.Buffer = true;            
            context.Response.AddHeader("content-disposition", "attachment; filename="
                + Convert.ToChar(34)
                + System.Web.HttpUtility.UrlPathEncode(filename)
                + Convert.ToChar(34));
            context.Response.Charset = "utf-8";
            context.Response.ContentType = "Application/octet-stream";
            string savepath = ConfigurationManager.AppSettings["UploadFilePath"].ToString() + foldername;            
            string path = context.Server.MapPath(savepath + "/" + filename);
            context.Response.WriteFile(path);
            context.Response.End();
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}